<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>Database Performance Dashboard</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<?php
	date_default_timezone_set("Asia/Singapore");
	
?> 
<!-- include all library files here -->
<?php 
	require_once "./bootstrap.php"; 
	global $cur_time;
	//$currTime=time();
	$currTime = $cur_time;
?>
<!-- get performance data -->
<?php
	if($_SESSION['user']==NULL)
		header('Location: index.php?error=0');
		
	$dbstat = new DbStat();
	$dbss = array();
	$dbss = $dbstat->getDuration(date('YmdHis',$currTime), date('YmdHis', $currTime+24*60*60));
	$averages=array();
	$averages = array('PCT_FREE_MEM'=>0, 'DIC_HR'=>0, 'PCT_RELOADS'=>0,
	'BUFFER_HR'=>0,'REDO_WAIT_R'=>0, 'IMM_ALLOC'=>0, 'IMM_COPY'=>0,
	'WAIT_ALLOC'=>0, 'WAIT_COPY'=>0, 'PCT_SORTS'=>0, 'ROLLBACK'=>0);
    //var_dump($dbss);
	foreach ($dbss as $dbs1) {
		$averages['PCT_FREE_MEM']+= $dbs1['PCT_FREE_MEM'];
		$averages['DIC_HR'] +=$dbs1['DIC_HR'];
          $averages['PCT_RELOADS'] +=$dbs1['PCT_RELOADS'];
          $averages['BUFFER_HR'] +=$dbs1['BUFFER_HR'];
          $averages['REDO_WAIT_R'] +=$dbs1['REDO_WAIT_R'];
          $averages['IMM_ALLOC'] +=$dbs1['IMM_ALLOC'];
          $averages['IMM_COPY'] +=$dbs1['IMM_COPY'];
          $averages['WAIT_ALLOC'] +=$dbs1['WAIT_ALLOC'];
          $averages['WAIT_COPY'] +=$dbs1['WAIT_COPY'];
          $averages['PCT_SORTS'] +=$dbs1['PCT_SORTS'];
          $averages['ROLLBACK'] +=$dbs1['ROLLBACK'];
        }
		if(sizeof($dbss) > 0) {
			$averages['PCT_FREE_MEM'] /= sizeof($dbss);
			$averages['DIC_HR'] /= sizeof($dbss);
			$averages['PCT_RELOADS'] /= sizeof($dbss);
			$averages['BUFFER_HR'] /= sizeof($dbss);
			$averages['REDO_WAIT_R'] /= sizeof($dbss);
			$averages['IMM_ALLOC'] /= sizeof($dbss);
			$averages['IMM_COPY'] /= sizeof($dbss);
			$averages['WAIT_ALLOC'] /= sizeof($dbss);
			$averages['WAIT_COPY'] /= sizeof($dbss);
			$averages['PCT_SORTS'] /= sizeof($dbss);
			$averages['ROLLBACK'] /= sizeof($dbss);
		} else {
			$averages['PCT_FREE_MEM'] = 0;
			$averages['DIC_HR'] = 0;
			$averages['PCT_RELOADS'] = 0;
			$averages['BUFFER_HR'] = 0;
			$averages['REDO_WAIT_R'] = 0;
			$averages['IMM_ALLOC'] = 0;
			$averages['IMM_COPY'] = 0;
			$averages['WAIT_ALLOC'] = 0;
			$averages['WAIT_COPY'] = 0;
			$averages['PCT_SORTS'] = 0;
			$averages['ROLLBACK'] = 0;
		}
?>
<?php 
	$uc = new UserConfig();
	$uc->get($_SESSION['user']);
?>
  <body>
    <div id="container">
      <!-- Start of Page Header -->
      <div id="page_header">
          <div id="company_name">
          <h1><span>Oracle Database Performance Dashboard</span></h1>
          </div>
      </div>
      <div id="page_menu">
          <ul>
          <li class="home"><a href="./index.php" title="Home"><span>Home</span></a></li>
          <li class="monitor"><a href="./firstlevel.php" title="First Level of Parameters Monitor"><span>Monitor</span></a></li>
          <li class="debug"><a href="./debug.php" title="Debug Interface"><span>Debug</span></a></li>
          <li class="settings"><a href="./settings.php" title="Settings"><span>Settings</span></a></li>
          <li class="aboutus"><a href="./aboutUs.php" title="About Us"><span>About Us</span></a></li>
          </ul>
      </div>
	  <div id="logout"><a href="./logout.php">logout</a></div>
      <div id="main_content">
          <div class="content_header">
          <h2><span>Database Performance Dashboard</span></h2>
          </div>
          <div class="content_box_right">
          <div class="content_box_left">
          <div class="content_box">
          <div id="main_content_border">
              <div class="topmasters">
                  <div class="thumbnail">
                  <img src="images/_thumbnail02.gif" width="133" height="93" alt="Thumbnail Caption" />
              </div>
              <div class="topmasters_info">
			  
                <h2>Shared Pool<form method="post" action="secondlevel_sp.php"><input type="submit" name="" value="View "></h2>
				<p><?php if($averages['PCT_FREE_MEM'] > $uc->getSecond('PCT_FREE_MEM')) {echo 'Tips: <font color="yellow">shared pool size might need to be reduced to avoid wastage</font>';}?></p>
                    <br />
                    <table class="newspaper-b">
					<tbody>
                    <tr>
					<td><b>Pct. of Free Memory: </b></td>
                    <td><?php echo number_format($averages['PCT_FREE_MEM'], 2) ?></td>
                    <td width="15%">
                    <?php 
					$first = $uc->getFirst('PCT_FREE_MEM');
					$second = $uc->getSecond('PCT_FREE_MEM');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['PCT_FREE_MEM'] <= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['PCT_FREE_MEM'] > $lower && $averages['PCT_FREE_MEM'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy!</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					
					?>
                    </td>
                    </tr>
                    <tr>
					<td><b>Dictionary Cache Hit Ratio: </b></td>
                    <td><?php echo number_format($averages['DIC_HR'], 2) ?></td><td>
                    <?php 
					$first = $uc->getFirst('DIC_HR');
					$second = $uc->getSecond('DIC_HR');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['DIC_HR']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['DIC_HR'] > $lower && $averages['DIC_HR'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    <tr>
					<td><b>Proportion of Reloads: </b></td>
                    <td><?php echo number_format($averages['PCT_RELOADS'], 2)?></td><td>
                    <?php $first = $uc->getFirst('PCT_RELOADS');
					$second = $uc->getSecond('PCT_RELOADS');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['PCT_RELOADS']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['PCT_RELOADS'] > $lower && $averages['PCT_RELOADS'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
					</tbody>
                    </table>
					</form>
                    <p />&nbsp;<br />
					
                <h2>Buffer Cache <form method="post" action="secondlevel_bc.php"><input type="submit" value="View Details"></h2>
                    <br />
                    <table class="newspaper-b">
                    <tr><td><b>Buffer Cache Hit Ratio: </b></td>
                    <td><?php echo number_format($averages['BUFFER_HR'], 2)?></td><td width="15%">
                    <?php $first = $uc->getFirst('BUFFER_HR');
					$second = $uc->getSecond('BUFFER_HR');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['BUFFER_HR']>=$upper ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['BUFFER_HR'] >= $lower && $averages['BUFFER_HR'] < $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    </table>
					</form>
                    <p />&nbsp;<br />
                <h2>Redo Log Buffer/Files <form method="post" action="secondlevel_redo.php"><input type="submit" value="View Details"></h2>
                    <br />
                    <table class="newspaper-b">
                    <tr><td><b>Redo Space Wait Ratio: </b></td>
                    <td><?php echo number_format($averages['REDO_WAIT_R'],2)?></td><td width="15%">
                    <?php $first = $uc->getFirst('REDO_WAIT_R');
					$second = $uc->getSecond('REDO_WAIT_R');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['REDO_WAIT_R']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['REDO_WAIT_R'] > $lower && $averages['REDO_WAIT_R'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    <tr><td><b>Redo Log Contention<b></td><td colspan="2"></td>
                    </tr>
                    <tr><td align="right">Immediate Contention of Redo Allocation: </td>
                    <td><?php echo number_format($averages['IMM_ALLOC'], 2)?></td><td>
                    <?php $first = $uc->getFirst('IMM_ALLOC');
					$second = $uc->getSecond('IMM_ALLOC');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['IMM_ALLOC']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['IMM_ALLOC'] > $lower && $averages['IMM_ALLOC'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    <tr><td align="right">Immediate Contention of Redo Copy: </td>
                    <td><?php echo number_format($averages['IMM_COPY'], 2)?></td><td>
                    <?php $first = $uc->getFirst('IMM_COPY');
					$second = $uc->getSecond('IMM_COPY');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['IMM_COPY']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['IMM_COPY'] > $lower && $averages['IMM_COPY'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    <tr><td align="right">Wait Contention of Redo Allocation: </td>
                    <td><?php echo number_format($averages['WAIT_ALLOC'], 2)?></td><td>
                    <?php $first = $uc->getFirst('WAIT_ALLOC');
					$second = $uc->getSecond('WAIT_ALLOC');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['WAIT_ALLOC']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['WAIT_ALLOC'] > $lower && $averages['WAIT_ALLOC'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    <tr><td align="right">Wait Contention of Redo Copy: </td>
                    <td><?php echo number_format($averages['WAIT_COPY'], 2)?></td><td>
                    <?php $first = $uc->getFirst('WAIT_COPY');
					$second = $uc->getSecond('WAIT_COPY');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['WAIT_COPY']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['WAIT_COPY'] > $lower && $averages['WAIT_COPY'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    </table>
					</form>
                    <p />&nbsp;<br />
                <h2>Memory Area used for Sorting <form method="post" action="secondlevel_sort.php"><input type="submit" value="View Details"></h2>
                    <br />
                    <table class="newspaper-b">
                    <tr><td><b>Data sorts occurred in Memory / in Disk: </b></td>
                    <td><?php echo number_format($averages['PCT_SORTS'], 2)?></td><td width="15%">
                    <?php $first = $uc->getFirst('PCT_SORTS');
					$second = $uc->getSecond('PCT_SORTS');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['PCT_SORTS']>= $upper ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['PCT_SORTS'] >= $lower && $averages['PCT_SORTS'] < $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    </table>
					</form>
                    <p />&nbsp;<br />
                <h2>Rollback Segments <form method="post" action="secondlevel_roll.php"><input type="submit" value="View Details"></h2>
                    <br />
                    <table class="newspaper-b">
                    <tr><td><b>Waits / Accesses to Rollback Segments: </b></td>
                    <td><?php echo number_format($averages['ROLLBACK'], 2)?></td><td width="15%">
                    <?php $first = $uc->getFirst('ROLLBACK');
					$second = $uc->getSecond('ROLLBACK');
					if ($first > $second) {
					$upper = $first;
					$lower = $second;
					} else {
					$upper = $second;
					$lower = $first;
					}
					if($averages['ROLLBACK']<= $lower ) {
					echo "<p class='healthy'>Healthy</p>";
					}
					elseif ($averages['ROLLBACK'] > $lower && $averages['ROLLBACK'] <= $upper) {
					echo "<p class='unhealthy'>Unhealthy</p>";
					}
					else {
					echo "<p class='serious'>Need DBA Attention!</p>";
					}
					?>
                    </td></tr>
                    </table>
					</form>
                    <p />&nbsp;<br />
                  </div>
                  <div class="clearthis">&nbsp;</div>
              </div>
  
              <!-- End of Top Masters Listing 1 -->
  
          </div>
          </div>
          </div>
          </div>
  
      </div>
  
      <!-- End of Main Content -->
  
  
      <div class="clearthis">&nbsp;</div>
  
  
      <!-- Start of Page Footer -->
  
      <div id="page_footer">
      Design by <a href="aboutUs.php">CS5226 Group</a>
      </div>
  
  </div>
  
  </body>
  </html>